/*
 * Copyright (c) 2020 - present, Inspur Genersoft Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.inspur.edp.formserver.vmmanager.config;

import com.inspur.edp.caf.cef.dt.spi.CommonStructureSchemaExtension;
import com.inspur.edp.formserver.rt.api.ViewModelRtService;
import com.inspur.edp.formserver.vmapi.ViewModelService;
import com.inspur.edp.formserver.vmmanager.commonstructure.VMComStructureSchemaExtension;
import com.inspur.edp.formserver.vmmanager.service.ViewModelRtServiceImpl;
import com.inspur.edp.formserver.vmmanager.service.ViewModelServiceImpl;
import com.inspur.edp.metadata.rtcustomization.api.CustomizationService;
import io.iec.edp.caf.securityentry.api.manager.SecurityEntryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration("com.inspur.edp.formserver.vmmanager.config.VMManagerConfig")
public class VMManagerConfig {
    @Bean("com.inspur.edp.formserver.vmmanager.config.VMManagerConfig.VMComStructureSchemaExtension()")
    public CommonStructureSchemaExtension getVMComStructureSchemaExtension() {
        return new VMComStructureSchemaExtension();
    }

    /**
     * 创建并注册ViewModelService的Spring Bean实例
     *
     * <p>该Bean的创建依赖于可选的安全入口服务{@link SecurityEntryService}：
     * <ul>
     *   <li>当存在{@code SecurityEntryService} Bean时，会注入并用于权限控制</li>
     *   <li>当不存在时(元数据部署工具场景)，将创建无权限控制的实例</li>
     * </ul>
     *
     * @param securityEntryService 可选依赖的安全入口服务，用于视图模型权限管理。
     *                            使用{@code @Autowired(required=false)}注解，
     *                            允许该参数为null
     * @return 已配置的{@link ViewModelService}实现实例
     * @see ViewModelServiceImpl 具体实现类
     */
    @Bean("com.inspur.edp.formserver.vmmanager.service.ViewModelServiceImpl")
    public ViewModelService getViewModelService(@Autowired(required = false) SecurityEntryService securityEntryService) {
        return new ViewModelServiceImpl(securityEntryService);
    }
    @Bean("com.inspur.edp.formserver.vmmanager.service.ViewModelRtServiceImpl")
    public ViewModelRtService getViewModelRtService(CustomizationService customizationService) {
        return new ViewModelRtServiceImpl(customizationService);
    }

}

